home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / expanded.lha / expanded / src / List.C < prev    next >
C/C++ Source or Header  |  1992-03-19  |  21KB  |  1,007 lines

  1. //
  2. // Linear-Affine-Projective Geometry Package
  3. //
  4. // List.C
  5. //
  6. // $Header$
  7. //
  8. // William J.R. Longabaugh 
  9. // University of Washington
  10. //
  11. // Implementation of the linear-affine-projective geometry
  12. // package described in William J.R. Longabaugh, "An Expanded
  13. // System for Coordinate-Free Geometric Programming", Master's 
  14. // thesis, University of Washington, 1992.
  15. //
  16. // Copyright (c) 1992, William J.R. Longabaugh
  17. //   Copying, use and development for non-commercial purposes permitted.
  18. //   All rights for commercial use reserved.
  19. //   This software is unsupported and without warranty; it is
  20. //   provided "as is".
  21. //
  22. // ***********************************************************************
  23.  
  24. #include "List.h"
  25.  
  26. // This implementation of lists is a prime candidate for templates
  27. // if it is implemented using a C++ compiler that supports them!
  28. // Since lists are defined to store and return elements (instead
  29. // of pointers to elements), the code needs to be duplicated
  30. // for each class.  Using any sort of inheritance would probably be
  31. // more trouble than it is worth in this instance.
  32.  
  33. // ***********************************************************************
  34. // ***********************************************************************
  35. //
  36. // ScalarList
  37. //
  38. // ***********************************************************************
  39. // ***********************************************************************
  40. //
  41. // Public member functions
  42. //
  43. // ***********************************************************************
  44.  
  45. ScalarList::ScalarList(ScalarList &t)
  46. {
  47.   size = t.Length();
  48.   if (size > MAX_LOCAL_LIST) {
  49.     list = new Scalar[size];
  50.   } else {
  51.     list = local;
  52.   }
  53.   for (int i = 0; i < size; i++) {
  54.     list[i] = t[i];
  55.   } 
  56. }
  57.  
  58. // ***********************************************************************
  59.  
  60. ScalarList::ScalarList(int n)
  61. {
  62.   size = n;
  63.   if (size > MAX_LOCAL_LIST) {
  64.     list = new Scalar[size];
  65.   } else {
  66.     list = local;
  67.   }
  68.   for (int i = 0; i < n; i++) {
  69.     list[i] = 0.0;
  70.   } 
  71. }
  72.  
  73. // ***********************************************************************
  74.  
  75. ScalarList::ScalarList(Scalar s, int n)
  76. {
  77.   size = n;
  78.   if (size > MAX_LOCAL_LIST) {
  79.     list = new Scalar[size];
  80.   } else {
  81.     list = local;
  82.   }
  83.   for (int i = 0; i < n; i++) {
  84.     list[i] = s;
  85.   } 
  86. }
  87.  
  88. // ***********************************************************************
  89.  
  90. ScalarList::ScalarList(Scalar s)
  91. {
  92.   list = local;
  93.   size = 1;
  94.   list[0] = s;
  95. }
  96.  
  97. // ***********************************************************************
  98.  
  99. ScalarList::ScalarList(Scalar s1, Scalar s2)
  100. {
  101.   list = local;
  102.   size = 2;
  103.   list[0] = s1;
  104.   list[1] = s2;
  105. }
  106.  
  107. // ***********************************************************************
  108.  
  109. ScalarList::ScalarList(Scalar s1, Scalar s2, Scalar s3)
  110. {
  111.   list = local;
  112.   size = 3;
  113.   list[0] = s1;
  114.   list[1] = s2;
  115.   list[2] = s3;
  116. }
  117.  
  118. // ***********************************************************************
  119.  
  120. ScalarList::ScalarList(Scalar s1, Scalar s2, Scalar s3, Scalar s4)
  121. {
  122.   list = local;
  123.   size = 4;
  124.   list[0] = s1;
  125.   list[1] = s2;
  126.   list[2] = s3;
  127.   list[3] = s4;
  128. }
  129.  
  130.  
  131. // ***********************************************************************
  132.  
  133. Scalar& ScalarList::operator[](int n)
  134. {
  135.   if ((n < 0) || (n >= size)) {
  136.     errh.ErrorExit("Scalar& ScalarList::operator[](int)",
  137.            "Index is out of range", ErrVal("Index = ", n), *this);
  138.   }
  139.   return list[n];
  140. }
  141.  
  142. // ***********************************************************************
  143.  
  144. ScalarList ScalarList::operator+(ScalarList &t)
  145. {
  146.   int i;
  147.   int newsize = size + t.Length();
  148.   ScalarList retval(newsize);
  149.   for (i = 0; i < size; i++) {
  150.     retval[i] = (*this)[i];
  151.   }
  152.   for (i = size; i < newsize; i++) {
  153.     retval[i] = t[i - size];
  154.   }
  155.   return (retval);
  156. }
  157.  
  158. // ***********************************************************************
  159.  
  160. ScalarList ScalarList::operator*(int i)
  161. {
  162.   int newsize = i * size;
  163.   ScalarList retval(newsize);
  164.   for (int k = 0; k < i; k++) {
  165.     for (int j = 0; j < size; j++) {
  166.       retval[(k * size) + j] = list[j];
  167.     }
  168.   }
  169.   return (retval);
  170. }
  171.  
  172. // ***********************************************************************
  173.  
  174. ScalarList& ScalarList::operator=(ScalarList &t)
  175. {
  176.   if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
  177.     delete list;
  178.   }
  179.  
  180.   size = t.Length();
  181.   if (size > MAX_LOCAL_LIST) {
  182.     list = new Scalar[size];
  183.   } else {
  184.     list = local;
  185.   }
  186.  
  187.   for (int i = 0; i < size; i++) {
  188.     list[i] = t[i];
  189.   } 
  190.   return (*this);
  191. }
  192.  
  193. // ***********************************************************************
  194. //
  195. // Destructor
  196. //
  197.  
  198. ScalarList::~ScalarList(void)
  199. {
  200.   if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
  201.     delete list;
  202.   }
  203. }
  204.  
  205. // ***********************************************************************
  206. //
  207. // To do debug printing:
  208. //
  209.  
  210. void ScalarList::debug_out(ostream &c, int indent)
  211. {
  212.   char *ibloc = new char[indent + 1];
  213.   for (int i = 0; i < indent; i++) {
  214.     *(ibloc + i) = ' ';
  215.   }
  216.   *(ibloc + indent) = '\0';
  217.  
  218.   c << ibloc << ast;
  219.   c << ibloc << "Scalar list\n";
  220.   c << ibloc << "Number of elements: " << size << "\n";
  221.   if (size > 0) {
  222.     c << ibloc << "Elements:";
  223.     c << ibloc;
  224.     for (int j = 0; j < size; j++) {
  225.       if (j % 4 == 0) {c << "\n" << ibloc;}
  226.       c << list[j] << "  ";
  227.     }
  228.     c << "\n";
  229.   }
  230.   c << ibloc << ast;
  231.  
  232.   delete ibloc;
  233.   return;
  234. }
  235.  
  236. // ***********************************************************************
  237. // ***********************************************************************
  238. //
  239. // IntList
  240. //
  241. // ***********************************************************************
  242. // ***********************************************************************
  243. //
  244. // Public member functions
  245. //
  246. // ***********************************************************************
  247.  
  248. IntList::IntList(IntList &t)
  249. {
  250.   size = t.Length();
  251.   if (size > MAX_LOCAL_LIST) {
  252.     list = new int[size];
  253.   } else {
  254.     list = local;
  255.   }
  256.   for (int i = 0; i < size; i++) {
  257.     list[i] = t[i];
  258.   } 
  259. }
  260.  
  261. // ***********************************************************************
  262.  
  263. IntList::IntList(int s)
  264. {
  265.   size = s;
  266.   if (size > MAX_LOCAL_LIST) {
  267.     list = new int[size];
  268.   } else {
  269.     list = local;
  270.   }
  271.   for (int i = 0; i < s; i++) {
  272.     list[i] = 0;
  273.   } 
  274. }
  275.  
  276. // ***********************************************************************
  277.  
  278. IntList::IntList(int val, int s)
  279. {
  280.   size = s;
  281.   if (size > MAX_LOCAL_LIST) {
  282.     list = new int[size];
  283.   } else {
  284.     list = local;
  285.   }
  286.   for (int i = 0; i < s; i++) {
  287.     list[i] = val;
  288.   } 
  289. }
  290.  
  291. // ***********************************************************************
  292.  
  293. IntList::IntList(int s1, int s2, int s3)
  294. {
  295.   list = local;
  296.   size = 3;
  297.   list[0] = s1;
  298.   list[1] = s2;
  299.   list[2] = s3;
  300. }
  301.  
  302. // ***********************************************************************
  303.  
  304. IntList::IntList(int s1, int s2, int s3, int s4)
  305. {
  306.   list = local;
  307.   size = 4;
  308.   list[0] = s1;
  309.   list[1] = s2;
  310.   list[2] = s3;
  311.   list[3] = s4;
  312. }
  313.  
  314. // ***********************************************************************
  315.  
  316. int& IntList::operator[](int n)
  317. {
  318.   if ((n < 0) || (n >= size)) {
  319.     errh.ErrorExit("int& IntList::operator[](int)",
  320.            "Index is out of range", ErrVal("Index = ", n), *this);
  321.   }
  322.   return list[n];
  323. }
  324.  
  325. // ***********************************************************************
  326.  
  327. IntList IntList::operator+(IntList &t)
  328. {
  329.   int i;
  330.   int newsize = size + t.Length();
  331.   IntList retval(newsize);
  332.   for (i = 0; i < size; i++) {
  333.     retval[i] = (*this)[i];
  334.   }
  335.   for (i = size; i < newsize; i++) {
  336.     retval[i] = t[i - size];
  337.   }
  338.   return (retval);
  339. }
  340.  
  341. // ***********************************************************************
  342.  
  343. IntList IntList::operator*(int i)
  344. {
  345.   int newsize = i * size;
  346.   IntList retval(newsize);
  347.   for (int k = 0; k < i; k++) {
  348.     for (int j = 0; j < size; j++) {
  349.       retval[(k * size) + j] = list[j];
  350.     }
  351.   }
  352.   return (retval);
  353. }
  354.  
  355. // ***********************************************************************
  356.  
  357. IntList& IntList::operator=(IntList &t)
  358. {
  359.   if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
  360.     delete list;
  361.   }
  362.  
  363.   size = t.Length();
  364.   if (size > MAX_LOCAL_LIST) {
  365.     list = new int[size];
  366.   } else {
  367.     list = local;
  368.   }
  369.  
  370.   for (int i = 0; i < size; i++) {
  371.     list[i] = t[i];
  372.   } 
  373.   return (*this);
  374. }
  375.  
  376. // ***********************************************************************
  377. //
  378. // Destructor
  379. //
  380.  
  381. IntList::~IntList(void)
  382. {
  383.   if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
  384.     delete list;
  385.   }
  386. }
  387.  
  388. // ***********************************************************************
  389. //
  390. // To do debug printing:
  391. //
  392.  
  393. void IntList::debug_out(ostream &c, int indent)
  394. {
  395.   char *ibloc = new char[indent + 1];
  396.   for (int i = 0; i < indent; i++) {
  397.     *(ibloc + i) = ' ';
  398.   }
  399.   *(ibloc + indent) = '\0';
  400.  
  401.   c << ibloc << ast;
  402.   c << ibloc << "Integer list\n";
  403.   c << ibloc << "Number of elements: " << size << "\n";
  404.   if (size > 0) {
  405.     c << ibloc << "Elements:";
  406.     c << ibloc;
  407.     for (int j = 0; j < size; j++) {
  408.       if (j % 4 == 0) {c << "\n" << ibloc;}
  409.       c << list[j] << "  ";
  410.     }
  411.     c << "\n";
  412.   }
  413.   c << ibloc << ast;
  414.  
  415.   delete ibloc;
  416.   return;
  417. }
  418.  
  419. // ***********************************************************************
  420. // ***********************************************************************
  421. //
  422. // GeObList
  423. //
  424. // ***********************************************************************
  425. // ***********************************************************************
  426. //
  427. // Public member functions
  428. //
  429. // ***********************************************************************
  430.  
  431. GeObList::GeObList(GeObList &t)
  432. {
  433.   size = t.Length();
  434.   if (size > MAX_LOCAL_LIST) {
  435.     list = new GeOb[size];
  436.   } else {
  437.     list = local;
  438.   }
  439.   for (int i = 0; i < size; i++) {
  440.     list[i] = t[i];
  441.   } 
  442. }
  443.  
  444. // ***********************************************************************
  445.  
  446. GeObList::GeObList(int n)
  447. {
  448.   size = n;
  449.   if (size > MAX_LOCAL_LIST) {
  450.     list = new GeOb[size];
  451.   } else {
  452.     list = local;
  453.   }
  454. }
  455.  
  456. // ***********************************************************************
  457.  
  458. GeObList::GeObList(GeOb &s, int n)
  459. {
  460.   size = n;
  461.   if (size > MAX_LOCAL_LIST) {
  462.     list = new GeOb[size];
  463.   } else {
  464.     list = local;
  465.   }
  466.   for (int i = 0; i < n; i++) {
  467.     list[i] = s;
  468.   } 
  469. }
  470.  
  471. // ***********************************************************************
  472.  
  473. GeObList::GeObList(GeOb &s)
  474. {
  475.   list = local;
  476.   size = 1;
  477.   list[0] = s;
  478. }
  479.  
  480. // ***********************************************************************
  481.  
  482. GeObList::GeObList(GeOb &s1, GeOb &s2)
  483. {
  484.   list = local;
  485.   size = 2;
  486.   list[0] = s1;
  487.   list[1] = s2;
  488. }
  489.  
  490. // ***********************************************************************
  491.  
  492. GeObList::GeObList(GeOb &s1, GeOb &s2, GeOb &s3)
  493. {
  494.   list = local;
  495.   size = 3;
  496.   list[0] = s1;
  497.   list[1] = s2;
  498.   list[2] = s3;
  499. }
  500.  
  501. // ***********************************************************************
  502.  
  503. GeObList::GeObList(GeOb &s1, GeOb &s2, GeOb &s3, GeOb &s4)
  504. {
  505.   list = local;
  506.   size = 4;
  507.   list[0] = s1;
  508.   list[1] = s2;
  509.   list[2] = s3;
  510.   list[3] = s4;
  511. }
  512.  
  513.  
  514. // ***********************************************************************
  515.  
  516. GeOb& GeObList::operator[](int n)
  517. {
  518.   if ((n < 0) || (n >= size)) {
  519.     errh.ErrorExit("GeOb& GeObList::operator[](int)",
  520.            "Index is out of range", ErrVal("Index = ", n), *this);
  521.   }
  522.   return list[n];
  523. }
  524.  
  525. // ***********************************************************************
  526.  
  527. GeObList GeObList::operator+(GeObList &t)
  528. {
  529.   int i;
  530.   int newsize = size + t.Length();
  531.   GeObList retval(newsize);
  532.   for (i = 0; i < size; i++) {
  533.     retval[i] = (*this)[i];
  534.   }
  535.   for (i = size; i < newsize; i++) {
  536.     retval[i] = t[i - size];
  537.   }
  538.   return (retval);
  539. }
  540.  
  541. // ***********************************************************************
  542.  
  543. GeObList GeObList::operator*(int i)
  544. {
  545.   int newsize = i * size;
  546.   GeObList retval(newsize);
  547.   for (int k = 0; k < i; k++) {
  548.     for (int j = 0; j < size; j++) {
  549.       retval[(k * size) + j] = list[j];
  550.     }
  551.   }
  552.   return (retval);
  553. }
  554.  
  555. // ***********************************************************************
  556.  
  557. GeObList& GeObList::operator=(GeObList &t)
  558. {
  559.   if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
  560.     delete [size] list;
  561.   }
  562.  
  563.   size = t.Length();
  564.   if (size > MAX_LOCAL_LIST) {
  565.     list = new GeOb[size];
  566.   } else {
  567.     list = local;
  568.   }
  569.  
  570.   for (int i = 0; i < size; i++) {
  571.     list[i] = t[i];
  572.   } 
  573.   return (*this);
  574. }
  575.  
  576. // ***********************************************************************
  577. //
  578. // Destructor
  579. //
  580.  
  581. GeObList::~GeObList(void)
  582. {
  583.   if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
  584.     delete [size] list;
  585.   }
  586. }
  587.  
  588. // ***********************************************************************
  589. //
  590. // To do debug printing:
  591. //
  592.  
  593. void GeObList::debug_out(ostream &c, int indent)
  594. {
  595.   char *ibloc = new char[indent + 1];
  596.   for (int i = 0; i < indent; i++) {
  597.     *(ibloc + i) = ' ';
  598.   }
  599.   *(ibloc + indent) = '\0';
  600.  
  601.   c << ibloc << ast;
  602.   c << ibloc << "GeOb list\n";
  603.   c << ibloc << "Number of elements: " << size << "\n";
  604.   if (size > 0) {
  605.     c << ibloc << "Elements:\n";
  606.     for (int j = 0; j < size; j++) {
  607.       list[j].debug_out(c, indent + ERR_IND);
  608.     }
  609.   }
  610.   c << ibloc << ast;
  611.  
  612.   delete ibloc;
  613.   return;
  614. }
  615.  
  616. // ***********************************************************************
  617. // ***********************************************************************
  618. //
  619. // SpaceList
  620. //
  621. // ***********************************************************************
  622. // ***********************************************************************
  623. //
  624. // Public member functions
  625. //
  626. // ***********************************************************************
  627.  
  628. SpaceList::SpaceList(SpaceList &t)
  629. {
  630.   size = t.Length();
  631.   if (size > MAX_LOCAL_LIST) {
  632.     list = new Space[size];
  633.   } else {
  634.     list = local;
  635.   }
  636.   for (int i = 0; i < size; i++) {
  637.     list[i] = t[i];
  638.   } 
  639. }
  640.  
  641. // ***********************************************************************
  642.  
  643. SpaceList::SpaceList(int n)
  644. {
  645.   size = n;
  646.   if (size > MAX_LOCAL_LIST) {
  647.     list = new Space[size];
  648.   } else {
  649.     list = local;
  650.   }
  651. }
  652.  
  653. // ***********************************************************************
  654.  
  655. SpaceList::SpaceList(Space &s, int n)
  656. {
  657.   size = n;
  658.   if (size > MAX_LOCAL_LIST) {
  659.     list = new Space[size];
  660.   } else {
  661.     list = local;
  662.   }
  663.   for (int i = 0; i < n; i++) {
  664.     list[i] = s;
  665.   } 
  666. }
  667.  
  668. // ***********************************************************************
  669.  
  670. SpaceList::SpaceList(Space &s)
  671. {
  672.   list = local;
  673.   size = 1;
  674.   list[0] = s;
  675. }
  676.  
  677. // ***********************************************************************
  678.  
  679. SpaceList::SpaceList(Space &s1, Space &s2)
  680. {
  681.   list = local;
  682.   size = 2;
  683.   list[0] = s1;
  684.   list[1] = s2;
  685. }
  686.  
  687. // ***********************************************************************
  688.  
  689. SpaceList::SpaceList(Space &s1, Space &s2, Space &s3)
  690. {
  691.   list = local;
  692.   size = 3;
  693.   list[0] = s1;
  694.   list[1] = s2;
  695.   list[2] = s3;
  696. }
  697.  
  698. // ***********************************************************************
  699.  
  700. SpaceList::SpaceList(Space &s1, Space &s2, Space &s3, Space &s4)
  701. {
  702.   list = local;
  703.   size = 4;
  704.   list[0] = s1;
  705.   list[1] = s2;
  706.   list[2] = s3;
  707.   list[3] = s4;
  708. }
  709.  
  710. // ***********************************************************************
  711.  
  712. Space& SpaceList::operator[](int n)
  713. {
  714.   if ((n < 0) || (n >= size)) {
  715.     errh.ErrorExit("Space& SpaceList::operator[](int)",
  716.            "Index is out of range", ErrVal("Index = ", n), *this);
  717.   }
  718.   return list[n];
  719. }
  720.  
  721. // ***********************************************************************
  722.  
  723. SpaceList SpaceList::operator+(SpaceList &t)
  724. {
  725.   int i;
  726.   int newsize = size + t.Length();
  727.   SpaceList retval(newsize);
  728.   for (i = 0; i < size; i++) {
  729.     retval[i] = (*this)[i];
  730.   }
  731.   for (i = size; i < newsize; i++) {
  732.     retval[i] = t[i - size];
  733.   }
  734.   return (retval);
  735. }
  736.  
  737. // ***********************************************************************
  738.  
  739. SpaceList SpaceList::operator*(int i)
  740. {
  741.   int newsize = i * size;
  742.   SpaceList retval(newsize);
  743.   for (int k = 0; k < i; k++) {
  744.     for (int j = 0; j < size; j++) {
  745.       retval[(k * size) + j] = list[j];
  746.     }
  747.   }
  748.   return (retval);
  749. }
  750.  
  751. // ***********************************************************************
  752.  
  753. SpaceList& SpaceList::operator=(SpaceList &t)
  754. {
  755.   if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
  756.     delete [size] list;
  757.   }
  758.  
  759.   size = t.Length();
  760.   if (size > MAX_LOCAL_LIST) {
  761.     list = new Space[size];
  762.   } else {
  763.     list = local;
  764.   }
  765.  
  766.   for (int i = 0; i < size; i++) {
  767.     list[i] = t[i];
  768.   } 
  769.   return (*this);
  770. }
  771.  
  772. // ***********************************************************************
  773. //
  774. // Destructor
  775. //
  776.  
  777. SpaceList::~SpaceList(void)
  778. {
  779.   if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
  780.     delete [size] list;
  781.   }
  782. }
  783.  
  784. // ***********************************************************************
  785. //
  786. // To do debug printing:
  787. //
  788.  
  789. void SpaceList::debug_out(ostream &c, int indent)
  790. {
  791.   char *ibloc = new char[indent + 1];
  792.   for (int i = 0; i < indent; i++) {
  793.     *(ibloc + i) = ' ';
  794.   }
  795.   *(ibloc + indent) = '\0';
  796.  
  797.   c << ibloc << ast;
  798.   c << ibloc << "Space list\n";
  799.   c << ibloc << "Number of elements: " << size << "\n";
  800.   if (size > 0) {
  801.     c << ibloc << "Elements:\n";
  802.     for (int j = 0; j < size; j++) {
  803.       list[j].debug_out(c, indent + ERR_IND);
  804.     }
  805.   }
  806.   c << ibloc << ast;
  807.  
  808.   delete ibloc;
  809.   return;
  810. }
  811.  
  812. // ***********************************************************************
  813. // ***********************************************************************
  814. //
  815. // BasisList
  816. //
  817. // ***********************************************************************
  818. // ***********************************************************************
  819. //
  820. // Public member functions
  821. //
  822. // ***********************************************************************
  823.  
  824. BasisList::BasisList(BasisList &t)
  825. {
  826.   size = t.Length();
  827.   if (size > MAX_LOCAL_LIST) {
  828.     list = new Basis[size];
  829.   } else {
  830.     list = local;
  831.   }
  832.   for (int i = 0; i < size; i++) {
  833.     list[i] = t[i];
  834.   } 
  835. }
  836.  
  837. // ***********************************************************************
  838.  
  839. BasisList::BasisList(int n)
  840. {
  841.   size = n;
  842.   if (size > MAX_LOCAL_LIST) {
  843.     list = new Basis[size];
  844.   } else {
  845.     list = local;
  846.   }
  847. }
  848.  
  849. // ***********************************************************************
  850.  
  851. BasisList::BasisList(Basis &s, int n)
  852. {
  853.   size = n;
  854.   if (size > MAX_LOCAL_LIST) {
  855.     list = new Basis[size];
  856.   } else {
  857.     list = local;
  858.   }
  859.   for (int i = 0; i < n; i++) {
  860.     list[i] = s;
  861.   } 
  862. }
  863.  
  864. // ***********************************************************************
  865.  
  866. BasisList::BasisList(Basis &s)
  867. {
  868.   list = local;
  869.   size = 1;
  870.   list[0] = s;
  871. }
  872.  
  873. // ***********************************************************************
  874.  
  875. BasisList::BasisList(Basis &s1, Basis &s2)
  876. {
  877.   list = local;
  878.   size = 2;
  879.   list[0] = s1;
  880.   list[1] = s2;
  881. }
  882.  
  883. // ***********************************************************************
  884.  
  885. BasisList::BasisList(Basis &s1, Basis &s2, Basis &s3)
  886. {
  887.   list = local;
  888.   size = 3;
  889.   list[0] = s1;
  890.   list[1] = s2;
  891.   list[2] = s3;
  892. }
  893.  
  894. // ***********************************************************************
  895.  
  896. BasisList::BasisList(Basis &s1, Basis &s2, Basis &s3, Basis &s4)
  897. {
  898.   list = local;
  899.   size = 4;
  900.   list[0] = s1;
  901.   list[1] = s2;
  902.   list[2] = s3;
  903.   list[3] = s4;
  904. }
  905.  
  906. // ***********************************************************************
  907.  
  908. Basis& BasisList::operator[](int n)
  909. {
  910.   if ((n < 0) || (n >= size)) {
  911.     errh.ErrorExit("Basis& BasisList::operator[](int n)",
  912.            "Index is out of range", ErrVal("Index = ", n), *this);
  913.   }
  914.   return list[n];
  915. }
  916.  
  917. // ***********************************************************************
  918.  
  919. BasisList BasisList::operator+(BasisList &t)
  920. {
  921.   int i;
  922.   int newsize = size + t.Length();
  923.   BasisList retval(newsize);
  924.   for (i = 0; i < size; i++) {
  925.     retval[i] = (*this)[i];
  926.   }
  927.   for (i = size; i < newsize; i++) {
  928.     retval[i] = t[i - size];
  929.   }
  930.   return (retval);
  931. }
  932.  
  933. // ***********************************************************************
  934.  
  935. BasisList BasisList::operator*(int i)
  936. {
  937.   int newsize = i * size;
  938.   BasisList retval(newsize);
  939.   for (int k = 0; k < i; k++) {
  940.     for (int j = 0; j < size; j++) {
  941.       retval[(k * size) + j] = list[j];
  942.     }
  943.   }
  944.   return (retval);
  945. }
  946.  
  947. // ***********************************************************************
  948.  
  949. BasisList& BasisList::operator=(BasisList &t)
  950. {
  951.   if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
  952.     delete [size] list;
  953.   }
  954.  
  955.   size = t.Length();
  956.   if (size > MAX_LOCAL_LIST) {
  957.     list = new Basis[size];
  958.   } else {
  959.     list = local;
  960.   }
  961.  
  962.   for (int i = 0; i < size; i++) {
  963.     list[i] = t[i];
  964.   } 
  965.   return (*this);
  966. }
  967.  
  968. // ***********************************************************************
  969. //
  970. // Destructor
  971.  
  972. BasisList::~BasisList(void)
  973. {
  974.   if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
  975.     delete [size] list;
  976.   }
  977. }
  978.  
  979. // ***********************************************************************
  980. //
  981. // To do debug printing:
  982.  
  983. void BasisList::debug_out(ostream &c, int indent)
  984. {
  985.   char *ibloc = new char[indent + 1];
  986.   for (int i = 0; i < indent; i++) {
  987.     *(ibloc + i) = ' ';
  988.   }
  989.   *(ibloc + indent) = '\0';
  990.  
  991.   c << ibloc << ast;
  992.   c << ibloc << "Basis list\n";
  993.   c << ibloc << "Number of elements: " << size << "\n";
  994.   if (size > 0) {
  995.     c << ibloc << "Elements:\n"; 
  996.     for (int j = 0; j < size; j++) {
  997.       list[j].debug_out(c, indent + ERR_IND);
  998.     }
  999.   }
  1000.   c << ibloc << ast;
  1001.  
  1002.   delete ibloc;
  1003.   return;
  1004. }
  1005.  
  1006. // ***********************************************************************
  1007.